@extends('admin.layout.global')

@section('css-plugins')
    <link href="{{ asset('style/plugins/bootstrap-switch/css/bootstrap3/bootstrap-switch.min.css') }}" rel="stylesheet">
    <link href="{{ asset('style/plugins/toastr/toastr.min.css') }}" rel="stylesheet">
@endsection

@section('css')
    <link href="{{ asset('style/admin/css/custom.css') }}" rel="stylesheet">
    <style>
        .pagination {
            margin: 0 0;
        }
    </style>
@endsection

@section('js-plugins')
    <script src="{{ asset('style/plugins/bootstrap-switch/js/bootstrap-switch.min.js') }}"></script>
    <script src="{{ asset('style/plugins/toastr/toastr.min.js') }}"></script>
@endsection

@section('js')
    <script>
        $(function(){
            toastr.options = {
                "progressBar": true,
                "positionClass": "toast-top-right",
                "timeOut": "1200",
            }
            $("[type='checkbox']").bootstrapSwitch();

            $("[type='checkbox']").on('switchChange.bootstrapSwitch', function(event, state) {
                var id = $(this).data('id');
                var display = 0;
                if(state)
                {
                    display = 1;
                }
                $.ajax({
                    url: "{{ action('Admin\Shop\StoreController@postDisplayClock') }}",
                    data: { id:id,display:display,_token:'{{ csrf_token() }}'},
                    type:'post',
                    success: function (data) {
                        var jsonData = JSON.parse(data);
                        if (jsonData.code)
                        {
                            toastr.success(jsonData.message);
                        } else {
                            toastr.error(jsonData.message);
                        }
                    }
                })
            });
        });
    </script>
@endsection

@section('content')
    <div class="body-content animated fadeIn">
        <div class="row">
            <div class="col-md-8">

                <!-- Start basic color table -->
                <div class="panel">
                    <div class="panel-heading">
                        <div class="pull-left">
                            <a href="{{ action('Admin\Shop\StoreController@getIndex') }}" class="btn btn-default btn-sm"><i class="fa fa-mail-reply"></i> 返回</a>
                            <a href="{{ action('Admin\Shop\StoreController@getClockAdd', ['storeID' => $store->id]) }}" class="btn btn-success btn-sm"><i class="fa fa-plus"></i> 添加</a>
                        </div>
                        <div class="clearfix"></div>
                    </div><!-- /.panel-heading -->
                    <div class="panel-body no-padding">
                        <div class="table-responsive" style="margin-top: -1px;">
                            <table class="table table-striped table-success">
                                <thead>
                                <tr>
                                    <th class="text-center border-right" >店名</th>
                                    <th>时间</th>
                                    <th>配送费</th>
                                    <th>价格底线</th>
                                    <th>低于底线配送费</th>
                                    <th>是否显示</th>
                                    <th class="text-center">{{ getLang('Tips', 'operation') }}</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($clock as $v)
                                    <tr>
                                        <td class="text-center border-right">{{ $store->name }}</td>
                                        <td>{{ $v->time }}</td>
                                        <td>{{ $v->price }}</td>
                                        <td>{{ $v->term }}</td>
                                        <td>{{ $v->priceTwo }}</td>
                                        <td><input class='switch' type="checkbox" data-id="{{ $v->id }}" @if($v->display) checked @else checked-false @endif data-size="mini" data-on-text="显示" data-off-text="不显示" data-label-width="0" data-on-color="success" data-off-color="danger"></td>
                                        <td class="text-center">
                                            <a href="{{ action('Admin\Shop\StoreController@getClockEdit', ['id' => $v->id]) }}" class="btn btn-primary btn-xs" data-toggle="tooltip" data-placement="top" data-original-title="修改"><i class="fa fa-pencil"></i></a>
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div><!-- /.table-responsive -->
                    </div><!-- /.panel-body -->
                    <div class="panel-footer">
                        <div class="row">
                            <div class="col-md-12">
                                <div style="text-align: center">
                                </div>
                            </div>
                        </div>
                    </div>
                </div><!-- /.panel -->
                <!--/ End basic color table -->

            </div><!-- /.col-md-12 -->
        </div>
    </div>
@endsection